<?php
namespace app\service;


use app\model\mongo\RandomNickNameMongo;
use app\model\RandomNickNameModel;

class RandomNickNameService
{
    //随机组合实况信息
    public static function getRandomInfos($num): array
    {
//        $lists=RandomNickNameMongo::selectRandomMore([
//            'status'=>1
//        ],$num,['nickname']);
//        $nicknames=array_column($lists,'nickname');
        $nicknames=RandomNickNameModel::where([
            'status'=>1
        ])->limit($num)->inRandomOrder()->pluck('nickname')->toArray();
        //获取商品名称信息
        $goodsTitles=GoodsService::getGoodsTitles();
        $goodsTitleNum=count($goodsTitles);
        //返回数据
        $data=[];
        foreach ($nicknames as $nickname){
            $randNum=rand(0,$goodsTitleNum-1);
            $data[]=[
                'nickname'      =>$nickname,
                'goods_title'   =>$goodsTitles[$randNum]??''
            ];
        }
        return $data;
    }

}